﻿using DocumentFormat.OpenXml.Drawing;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Interop;

namespace Test.Generate
{
    internal class GenerateAudio
    {
        public static string getPsText(string inText)
        {
            string text = "<speak><phoneme alphabet=\"ipa\" ph=\""+ inText + "\">a</phoneme><break time=\"0.5s\"></break><phoneme alphabet=\"ipa\" ph=\""+ inText + "\">a</phoneme></speak>";
            return text;
        }

        public static async Task exec()
        {
            string[][] PSList = new string[][]
            {
                new string[] { "元音", "/ɑː/", "car、park、far", "We drive the car to the far park.", "我们开车去远的公园。" },
                new string[] { "元音", "/ʌ/", "duck、sun、cup", "Under the sun, the duck knocks the cup.", "太阳下，鸭子碰倒了杯子。" },
                new string[] { "元音", "/ɔː/", "horse、door、floor", "The horse stands by the door; toy’s on floor.", "马站在门旁，地板上有玩具。" },
                new string[] { "元音", "/ɒ/",  "dog、hot、box", "On a hot day, the dog pushes the box.", "热天里，狗推盒子。" },
                new string[] { "元音", "/ɜː/", "girl、skirt、bird", "The girl in a skirt feeds the bird.", "穿裙子的女孩喂小鸟。" },
                new string[] { "元音", "/ə/", "sister、doctor、about", "My sister talks about it with the doctor.", "姐姐和医生谈事情。" },
                new string[] { "元音", "/iː/", "bee、tree、tea", "The big pig sits on the ground.", "大大的猪坐在地上。" },
                new string[] { "元音", "/uː/", "zoo、school、food", "We take food from school to the zoo.", "我们从学校带食物去动物园。" },
                new string[] { "元音", "/ʊ/", "cook、book、good", "Mom cooks a good meal; we read books.", "妈妈做好饭，我们看书。" },
                new string[] { "元音", "/e/", "pen、red、bed", "The red pen is under the bed.", "红钢笔在床下面。" },
                new string[] { "元音", "/æ/", "cat、hat、bag", "The cat with a hat takes the bag.", "戴帽的猫拿书包。" },
                new string[] { "元音", "/eɪ/", "cake、make、face", "Lily makes a cake like her face.", "莉莉做的蛋糕像她的脸。" },
                new string[] { "元音", "/aɪ/", "bike、ice、like", "I like to ride a bike for ice cream.", "我喜欢骑车买冰淇淋。" },
                new string[] { "元音", "/ɔɪ/", "boy、toy、joy", "The boy plays with toys with joy.", "男孩玩玩具很开心。" },
                new string[] { "元音", "/əʊ/", "home、coat、boat", "Go home, put on coat, see the boat.", "回家穿外套，去看小船。" },
                new string[] { "元音", "/aʊ/", "cow、house、out", "The cow goes out of the house.", "奶牛走出房子。" },
                new string[] { "元音", "/ɪə/", "near、hear、ear", "Come near, hear the sound by my ear.", "靠近点，听我耳朵边的声。" },
                new string[] { "元音", "/eə/", "air、bear、pear", "The bear eats pears in fresh air.", "熊在空气里吃梨。" },
                new string[] { "元音", "/ʊə/", "tour、sure、pure", "I’m sure the tour has pure views.", "我确定旅行能看洁净的风景。" },
                new string[] { "辅音", "/p/", "pen、pig、cap", "The pig takes the pen and puts it in the cap.", "我们从学校带食物去动物园。" },
                new string[] { "辅音", "/b/", "bed、big、bag", "The big bag is next to the bed.", "大书包放在床的旁边。" },
                new string[] { "辅音", "/t/", "tea、cat、hat", "The cat wears a hat and drinks hot tea.", "小猫戴帽子，喝着热茶。" },
                new string[] { "辅音", "/d/", "dog、desk、door", "The dog is by the desk, looking at the door.", "小狗在书桌旁，看着门。" },
                new string[] { "辅音", "/k/", "cake、car、desk", "The desk near the car has a cake on it.", "汽车旁的书桌，放着蛋糕。" },
                new string[] { "辅音", "/g/", "girl、dog、goat", "The girl and the dog look at the goat.", "女孩和狗，看着山羊。" },
                new string[] { "辅音", "/f/", "fish、fan、fat", "The fat cat plays with a small fish near the fan.", "胖猫在风扇旁玩小鱼。" },
                new string[] { "辅音", "/v/", "van、vest、five", "Five vests are put in the van.", "五件背心放在货车里。" },
                new string[] { "辅音", "/s/", "sun、bus、sit", "Under the sun, someone sits near the bus.", "太阳下，有人坐在公交车旁。" },
                new string[] { "辅音", "/z/", "Zoo、zebra、is", "The zebra is in the zoo.", "这只斑马在动物园里。" },
                new string[] { "辅音", "/θ/", "three、thin、thumb", "The thin boy holds up three thumbs.", "瘦男孩竖起三根拇指。" },
                new string[] { "辅音", "/ð/", "this、that、those", "This schoolbag and those pencils are all new.", "这个书包和那些铅笔都是新的。" },
                new string[] { "辅音", "/ʃ/", "shop、shirt、sheep", "Buy a shirt with sheep pictures in the shop.", "在商店买印着绵羊的衬衫。" },
                new string[] { "辅音", "/ʒ/", "pleasure、treasure、leisure", "We open small treasures in our leisure and feel much pleasure.", "空闲时拆小礼物，我们特别开心。" },
                new string[] { "辅音", "/h/", "hello、high、happy", "Be high and happy.", "要兴致高昂，开开心心的。" },
                new string[] { "辅音", "/r/", "read、grass、rain", "I read by grass in rain.", "我在雨中，我在草地旁阅读。" },
                new string[] { "辅音", "/tʃ/", "chair、chick、watch", "The chick sits on the chair and looks at the watch.", "小鸡坐在椅子上，看着手表。" },
                new string[] { "辅音", "/dʒ/", "jam、juice、jar", "Put the jam and juice into the jar.", "把果酱和果汁放进罐子里。" },
                new string[] { "辅音", "/tr/", "tree、train、try", "Try to wait for the train near the tree.", "试着在树旁等火车。" },
                new string[] { "辅音", "/dr/", "drink、dress、dry", "The girl in a dress drinks water and dries the cup.", "穿连衣裙的女孩喝完水，擦干杯子。" },
                new string[] { "辅音", "/ts/", "cats、hats、seats", "The cats with hats sit on the seats.", "猫戴帽子，坐在座位上。" },
                new string[] { "辅音", "/dz/", "kids、hands、cards", "The kids hold some cards in their hands.", "小孩用手拿着一些卡片。" },
                new string[] { "辅音", "/m/", "mom、milk、map", "Mom takes milk and looks at the map.", "妈妈拿牛奶，看着地图。" },
                new string[] { "辅音", "/n/", "new、nine、name", "I write my name in the new notebook.", "我在新笔记本上写自己的名字。" },
                new string[] { "辅音", "/ŋ/", "sing、song、bring", "Mom brings a cake, and we sing a birthday song.", "妈妈带来蛋糕，我们唱生日歌。" },
                new string[] { "辅音", "/j/", "yes、yellow、you", "Do you like yellow? Yes.", "你喜欢黄色？是的。" },
                new string[] { "辅音", "/w/", "With、what、white", "What is that with white?", "那个带有白色的东西是什么？" },
                new string[] { "辅音", "/l/", "Like、apple、school", "I like apples at school.", "我在学校喜欢苹果。" },
            };

            // 示例：使用 EPPlus 创建 Excel 文件
            // 添加这行代码来设置许可证上下文
            ExcelPackage.License.SetNonCommercialPersonal("nx5");
            using (var package = new ExcelPackage())
            {
                // 添加工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");
                worksheet.Cells["A1"].Value = "类型";
                worksheet.Cells["B1"].Value = "音标";
                worksheet.Cells["D1"].Value = "单词";
                worksheet.Cells["E1"].Value = "单词音频";
                worksheet.Cells["F1"].Value = "例句";
                worksheet.Cells["G1"].Value = "例句音频";
                worksheet.Cells["H1"].Value = "翻译";

                for (int i = 0; i < PSList.Length; i++)
                {
                    //string psAudio = await SDKs.AIDoubao.AIAudio(getPsText(PSList[i][1].Replace("/", "")), "ssml");
                    //string wordAudio = await SDKs.AIDoubao.AIAudio(PSList[i][2], PSList[i][2]);
                    //await SDKs.AIDoubao.AIAudio(PSList[i][2].Split('、')[0], PSList[i][2]);
                    //await SDKs.AIDoubao.AIAudio(PSList[i][2].Split('、')[1], PSList[i][2]);
                    //await SDKs.AIDoubao.AIAudio(PSList[i][2].Split('、')[2], PSList[i][2]);
                    //string sentenceAudio = await SDKs.AIDoubao.AIAudio(PSList[i][3], PSList[i][2]);

                    string wordAudio = await SDKs.AIDoubao.AIAudio(PSList[i][2]);
                    await SDKs.AIDoubao.AIAudio(PSList[i][2].Split('、')[0]);
                    await SDKs.AIDoubao.AIAudio(PSList[i][2].Split('、')[1]);
                    await SDKs.AIDoubao.AIAudio(PSList[i][2].Split('、')[2]);
                    string sentenceAudio = await SDKs.AIDoubao.AIAudio(PSList[i][3]);


                    // 添加数据
                    worksheet.Cells["A" + (i + 2)].Value = PSList[i][0];
                    worksheet.Cells["B" + (i + 2)].Value = PSList[i][1];
                    worksheet.Cells["D" + (i + 2)].Value = PSList[i][2];
                    worksheet.Cells["E" + (i + 2)].Value = wordAudio;
                    worksheet.Cells["F" + (i + 2)].Value = PSList[i][3];
                    worksheet.Cells["G" + (i + 2)].Value = sentenceAudio;
                    worksheet.Cells["H" + (i + 2)].Value = PSList[i][4];
                    
                }

                // 保存到指定路径
                var filePath = @"D:\Webs\NX5\example.xlsx";
                FileInfo fileInfo = new FileInfo(filePath);
                package.SaveAs(fileInfo);
            }

        }
    }
}
